package com.ruoyi.attendance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.attendance.domain.AttendancePolicies;
import com.ruoyi.attendance.service.IAttendancePoliciesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考勤政策/排班详情Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@Slf4j
@RestController
@RequestMapping("/attendance/policies")
public class AttendancePoliciesController extends BaseController
{
    @Autowired
    private IAttendancePoliciesService attendancePoliciesService;

    /**
     * 查询考勤政策/排班详情列表
     */
    @PreAuthorize("@ss.hasPermi('attendance:policies:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttendancePolicies attendancePolicies)
    {
        startPage();
        List<AttendancePolicies> list = attendancePoliciesService.selectAttendancePoliciesList(attendancePolicies);
        return getDataTable(list);
    }

    /**
     * 导出考勤政策/排班详情列表
     */
    @PreAuthorize("@ss.hasPermi('attendance:policies:export')")
    @Log(title = "考勤政策/排班详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendancePolicies attendancePolicies)
    {
        List<AttendancePolicies> list = attendancePoliciesService.selectAttendancePoliciesList(attendancePolicies);
        ExcelUtil<AttendancePolicies> util = new ExcelUtil<AttendancePolicies>(AttendancePolicies.class);
        util.exportExcel(response, list, "考勤政策/排班详情数据");
    }

    /**
     * 获取考勤政策/排班详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('attendance:policies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attendancePoliciesService.selectAttendancePoliciesById(id));
    }

    /**
     * 新增考勤政策/排班详情
     */
    @PreAuthorize("@ss.hasPermi('attendance:policies:add')")
    @Log(title = "考勤政策/排班详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendancePolicies attendancePolicies)
    {
        log.info("这是/attendance/policies接口的post请求\n参数attendancePolicies={}", attendancePolicies);
        return toAjax(attendancePoliciesService.insertAttendancePolicies(attendancePolicies));
    }

    /**
     * 修改考勤政策/排班详情
     */
    @PreAuthorize("@ss.hasPermi('attendance:policies:edit')")
    @Log(title = "考勤政策/排班详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendancePolicies attendancePolicies)
    {
        return toAjax(attendancePoliciesService.updateAttendancePolicies(attendancePolicies));
    }

    /**
     * 删除考勤政策/排班详情
     */
    @PreAuthorize("@ss.hasPermi('attendance:policies:remove')")
    @Log(title = "考勤政策/排班详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendancePoliciesService.deleteAttendancePoliciesByIds(ids));
    }
}
